package com.example.administrator.xinyutg.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.xinyutg.R;
import com.example.administrator.xinyutg.bean.GroupData;
import com.example.administrator.xinyutg.task.ImageTask;

import java.util.List;

/**
 * Created by Administrator on 2015/9/26.
 */
public class DataAdapter extends AppBaseAdapter<GroupData> {
    public DataAdapter(List<GroupData> list, Context context) {
        super(list, context);
    }

    @Override
    public View getItemView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView==null){
            convertView=inflater.inflate(R.layout.item_fragment_shared,null);
            holder=new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }

        //映射数据
        holder.ivImg.setImageResource(R.mipmap.ic_launcher);
        holder.ivImg.setTag(list.get(position).getImageSmall());
        //启动异步任务下载图片
        new ImageTask(holder.ivImg).execute(list.get(position).getImageSmall());

        holder.tvProduct.setText(list.get(position).getProduct());
        holder.tvDiatance.setText("3.5km");
        holder.tvSummary.setText(list.get(position).getSummary());
        holder.tvTeamPrice.setText(list.get(position).getTeam_price());
        holder.tvMarketPrice.setText(list.get(position).getMarket_price());
        holder.tvNowNumber.setText(list.get(position).getNow_number());

        return convertView;
    }

    public class ViewHolder{
        private ImageView ivImg;
        private TextView tvProduct;
        private TextView tvDiatance;
        private TextView tvSummary;
        private TextView tvTeamPrice;
        private TextView tvMarketPrice;
        private TextView tvNowNumber;

        public ViewHolder(View convertView) {
            ivImg= (ImageView) convertView.findViewById(R.id.iv_image);
            tvProduct= (TextView) convertView.findViewById(R.id.tv_product);
            tvDiatance= (TextView) convertView.findViewById(R.id.tv_diatance);
            tvSummary= (TextView) convertView.findViewById(R.id.tv_summary);
            tvTeamPrice= (TextView) convertView.findViewById(R.id.tv_team_price);
            tvMarketPrice= (TextView) convertView.findViewById(R.id.tv_market_price);
            tvNowNumber= (TextView) convertView.findViewById(R.id.tv_now_number);
        }
    }
}
